home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
science
/
cdrift3.zip
/
SUN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-02-22
|
4KB
|
95 lines
/* This program is Copyright (c) 1990 David Allen. It may be freely
distributed as long as you leave my name and copyright notice on it.
I'd really like your comments and feedback; send e-mail to
davea@vlsi.ll.mit.edu, or send us-mail to David Allen, 10 O'Moore Ave,
Maynard, MA 01754. */
/* This file contains code to run tec under Un*x and Sunview. The
random number code is the same as that contained in unix.c; the
graphics code was inspired by the example code from Sun contained
in /usr/share/src/sun/suntool/examples/coloredit.c and in the
Sunview Programmer's Guide. I don't claim to understand it. The
code in draw() is similar to that in ami.c. */
#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include "const.h"
#include "var.h"
extern short step, phead; /* Defined in tec1.c */
extern unsigned char t[2][MAXX][MAXY]; /* Defined in tec1.c */
/* These arrays define similar colors to those in ami.c; the first two
are black, followed by two blues, four greens, four reds, four purples,
four greys, and a bunch of bright whites. */
unsigned char red [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0xb0, 0xd0, 0xf0,
0x90, 0xb0, 0xd0, 0xf0, 0x90, 0xb0, 0xd0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0 };
unsigned char green [] = {
0x00, 0x00, 0x00, 0x00, 0x90, 0xb0, 0xd0, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x90, 0xb0, 0xd0, 0xf0, 0x90, 0xb0, 0xd0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0 };
unsigned char blue [] = {
0x00, 0x00, 0xd0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x90, 0xb0, 0xd0, 0xf0, 0x90, 0xb0, 0xd0, 0xf0, 0x00, 0x00, 0x00, 0x00,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0 };
Pixwin *pw;
struct rect tr = { 0, 0, MAXX * 6, MAXY * 6 };
tecdestroy (c, s) Notify_client c; Destroy_status s; { step = MAXSTEP; }
/* A function called when the user tells Sunview to exit; it tells main()
that its time is up, so main can exit after finishing the current step */
main (argc, argv) int argc; char **argv; {
struct timeb t;
Frame base_frame;
Canvas canvas;
char cmsname[CMS_NAMESIZE];
/* Initialize random number generator */
ftime (&t); srandom ((int) ((t.time % 100000) + t.millitm));
/* Suntools-specific graphics setup */
base_frame = window_create (NULL, FRAME, FRAME_LABEL, "suntec",
WIN_WIDTH, MAXX * 6, WIN_HEIGHT, MAXY*6, 0);
canvas = window_create (base_frame, CANVAS, WIN_WIDTH,
MAXX * 6, WIN_HEIGHT, MAXY * 6, 0);
pw = (Pixwin *) canvas_pixwin (canvas);
sprintf (cmsname, "suntec%D", getpid());
pw_setcmsname (pw, cmsname);
pw_putcolormap (pw, 0, 32, red, green, blue);
notify_interpose_destroy_func (base_frame, tecdestroy);
window_set (base_frame, WIN_SHOW, TRUE, 0);
/* Run the program, checking with Sunview after each step */
init (*++argv);
for (step=0; step<MAXSTEP; step++) { onestep (); notify_dispatch (); }
exit (0); }
rnd (top) short top; { return (random () % top); }
panic (s) char *s; { printf ("PANIC: %s\n", s); exit (1); }
draw (src) short src; {
register short i, j, k, x;
pw_lock (pw, &tr);
for (j=0, i=0; j<YSIZE; j++, i=0) {
top: x = t[src][i][j] >> 2;
k = i+1; while (((t[src][k][j] >> 2) == x) && (k < XSIZE-1)) k++;
pw_rop (pw, i*6, j*6, (k-i)*6, 6, PIX_SRC | PIX_COLOR (x), NULL, 0, 0);
i = k-1;
if (i < XSIZE-1) { i++; goto top; } }
pw_unlock (pw); }